package com.zgzg.shop.pay.base.exception;


import com.zgzg.shop.pay.base.enums.ApiCode;
import org.apache.commons.lang3.StringUtils;

/**
 * @author: lzg
 * @description:
 */
public class CustomException extends RuntimeException {
    private final ApiCode apiCode;
    private final String message;

    public CustomException(ApiCode apiCode) {
        this(apiCode, null);
    }

    public CustomException(ApiCode apiCode, Object message) {
        this.apiCode = apiCode;
        String msg = apiCode.getMsg();
        if (message != null) {
            if (message instanceof String) {
                msg += "：" + message;
            } else {
                msg += "：" + message.toString();
            }
        }
        this.message = msg;
    }

    public CustomException(ApiCode apiCode, String message, Throwable cause) {
        super(StringUtils.isBlank(message) ? apiCode.getMsg() : apiCode.getMsg() + "：" + message, cause);
        this.apiCode = apiCode;
        this.message = super.getMessage();
    }



    public ApiCode getApiCode() {
        return apiCode;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
